// JavaScript Document
// version 1.1
function initTab( tabBtnBarId,tabContentId )
{
	var btns;
	var lis;
	var barElement = document.getElementById(tabBtnBarId);
	var contentElement = document.getElementById(tabContentId);
			
	btns = barElement.getElementsByTagName("a");
	var temp = contentElement.getElementsByTagName("li");
	lis = new Array();
	for( var l = 0 ; l<temp.length ; l++ )
	{
		if (temp[l].parentElement == contentElement)
		{
			lis.push(temp[l]);	
		}
	}
	temp = null;
	if( btns.length != lis.length)
	{
		alert("tab init failed");
		return;
	}
			
	for( var i = 0 ; i < btns.length ; i++ )
	{
		addEvent(btns[i],i,btns,lis);
	}
	//alert("after replace:\"" + changeCss("current my current","","none") + "\"");
}
function addEvent(element,index,btns,lis)
{
	element.onclick = function(){ onMouseOver(index,btns,lis); };
}
function onMouseOver(index,btns,lis)
{
	for( var i = 0 ; i < btns.length ; i ++ )
	{
		if( i == index )
		{
			btns[i].className = changeCss( btns[i].className , "","current");
			lis[i].className = changeCss( lis[i].className , "none","display");
			//btns[i].className = "current";
			//lis[i].className = "display";
		}
		else
		{
			btns[i].className = changeCss( btns[i].className , "current","");
			lis[i].className = changeCss( lis[i].className , "display","none");
			//btns[i].className = "";
			//lis[i].className = "none";
		}
	}
}

function changeCss( src, target , to )
{
	var csss = src.split(" ");
	var result = "";
	var bfind = false;
	
	for(var i = 0 ; i < csss.length ; i ++ )
	{
		if( csss[i] != " " )
		{
			if( csss[i] == target )	
			{
				result += (to + " ");	
				bfind = true;
			}
			else
			{
				result += (csss[i] + " ");	
			}
		}	
	}
	
	if( !bfind && to.length > 0)
		result = to + " " + result;	
	if( result.length != 0)
	{
		result = result.substr(0,result.length - 1);
	}
		
			

	return result;
}